package Persistance;

import Model.LoginCredential;
import Model.User;

import java.util.ArrayList;

public class UserList {

    private ArrayList<User> userList;

    public UserList(){
        userList = new ArrayList<User>();
        User firstUser = new User("Admin", "admin@admin.com", "180066544",
                createLoginCredentialsWithPassword("password1"));
        addUserToList(firstUser);

        User secondUser = new User("Abhishek", "abhishek@gmail.com", "1800555222",
                createLoginCredentialsWithPassword("password1"));
        addUserToList(secondUser);

    }

    public ArrayList<User> getUserList(){
        return this.userList;
    }

    private LoginCredential createLoginCredentialsWithPassword(String password){
        int username = 1111111;
        if(!userList.isEmpty())
            username = getLastUsername()+1;
        return new LoginCredential(username, password);
    }

    private int getUserListSize(){
        return userList.size();
    }

    private int getLastUsername(){
        User user = userList.get(getUserListSize()-1);
        return user.getLoginCredentials().getIntegerUsername();
    }

    private void addUserToList(User user){
        this.userList.add(user);
    }

}
